﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
using BaseDll;
using CommonTools;
using Newtonsoft.Json.Linq;
using Sunny.UI;
using UserData;
using static UserData.Control_ScrewData;

namespace StationDemo
{
    public partial class Form_Manual : UIPage

    {
        string strStationName = "";
        public Form_Manual(string name)
        {
            strStationName = name;
            InitializeComponent();
        }
        private void Function_遍历控件(Control control)
        {

            foreach (var item in control.Controls)
            {
                if (item is Interface_UserControl)
                {
                    ((Interface_UserControl)item).Init();
                }
                else
                {
                    Function_遍历控件((Control)item);
                }

            }


        }
    

     

        private void btn_start_Click(object sender, EventArgs e)
        {
            LogHelper.OnTest_ShowLog("手动界面日志", $"启动");
            LoadSeverMgr.Instance.Start();
          
        }

        private void btn_Stop_Click(object sender, EventArgs e)
        {
            LogHelper.OnTest_ShowLog("手动界面日志", $"停止");
            LoadSeverMgr.Instance.Stop();
            
        }

        private void btn_点亮_Click(object sender, EventArgs e)
        {

            LogHelper.OnTest_ShowLog("手动界面日志", $"开始点亮");

            double voltage = 0.0;
            double current = 0.0;
            bool res =  LoadSeverMgr.Instance.Function_点亮("", ref voltage, ref current);


            if (res)
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"点亮成功");
            }
            else 
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"点亮失败");
            }
         
        }

        private void btn_取图_Click(object sender, EventArgs e)
        {

            LogHelper.OnTest_ShowLog("手动界面日志", $"开始取图");

            double voltage = 0.0;
            double current = 0.0;
            bool res = LoadSeverMgr.Instance.Function_取图(0);


            if (res)
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"取图成功");
            }
            else
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"取图失败");
            }
        }

        private void btn_烧录_Click(object sender, EventArgs e)
        {
            LogHelper.OnTest_ShowLog("手动界面日志", $"开始烧录");

            double voltage = 0.0;
            double current = 0.0;
            bool res = LoadSeverMgr.Instance.Function_烧录(100000);


            if (res)
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"烧录成功");
            }
            else
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"烧录失败");
            }
        }

       

        private void btn_测试_Click(object sender, EventArgs e)
        {
            LogHelper.OnTest_ShowLog("手动界面日志", $"开始标定计算");
            double[] value = null;
            bool b_CalibResult = LoadSeverMgr.Instance.Function_标定计算(out value, false, 100000);

            if (b_CalibResult)
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"标定计算完成");
            }
            else
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"标定计算失败");
            }
        }

        private void btn_停止取图_Click(object sender, EventArgs e)
        {
            LoadSeverMgr.Instance.Functio_停止取图();

        }

      
       

        private void btn_对心计算_Click(object sender, EventArgs e)
        {

            LogHelper.OnTest_ShowLog("手动界面日志", $"对心计算开始");

            double[] value = null;
            bool res = LoadSeverMgr.Instance.Function_对心(out value);
            if (res)
            {
                
                LogHelper.OnTest_ShowLog("手动界面日志", $"对心计算完成，X = {value[0]},Y = {value[1]}");
            }
            else
            {
                LogHelper.OnTest_ShowLog("手动界面日志", $"对心计算失败");
            }
        }

        private void Form_Manual_Initialize(object sender, EventArgs e)
        {

        }

        private void Form_Manual_Load(object sender, EventArgs e)
        {
            Function_遍历控件(this);
        }
    }
}
